package ambika.JDBC;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Blob;
import com.mysql.jdbc.PreparedStatement;

public class JDBCapp {
	private static final String conString = "jdbc:mysql://localhost:3306/EmployeeData";
	
public void getEmployeeData() throws SQLException{ 
	Connection con = DriverManager.getConnection(conString, "username", "password");
	Statement stmt =con.createStatement();
	ResultSet rs = stmt
	.executeQuery("select  * from Employee");
	
	while(rs.next()){
		System.out.println(rs.getLong("EmpNum"));
		System.out.println(rs.getString("EmpActive"));
		System.out.println(rs.getString("EmpLastName"));
		System.out.println(rs.getString("EmpFirstName"));
	}
	rs.close();
	con.close();

}

public void insertEmployeeData(Long empDocID, Long empNum,String empDocCategory, String empDocType, Date empDocDate, Blob empDocContent, Date empDocExpiry, String empDocType_Category) throws SQLException{
	Connection con = DriverManager.getConnection(conString, "username", "password");
	PreparedStatement ps = (PreparedStatement) con.createStatement();
	ps.setLong(1, empDocID);
	ps.setLong(2, empNum);
	ps.setString(3, empDocCategory);
	ps.setString(4, empDocType);
	ps.setDate(5, empDocDate);
	ps.setBlob(6, empDocContent);
	ResultSet rs = ps.executeQuery("insert into EmpDoc(empNum, empDocCategory, empDocType, empDocDate, empDocContent, empDocExpiry) values(?,?,?,?,?,?)");
	while(rs.next()){
		Long eDID = rs.getLong("empDocID");
		Long eNum = rs.getLong("empNum");
		String eDocCategory = rs.getString("empDocCategory");
		String eDocType = rs.getString("empDocType");
		Date eDocDate = rs.getDate("empDocDate");
		Blob eDocContent = (Blob) rs.getBlob("empDocContent");
		System.out.println(eDID +""+eNum+""+eDocCategory+""+eDocType+""+eDocDate+""+eDocContent);
	
	}
	
}

public static void main(String[] args){
	JDBCapp app = new JDBCapp();
	try{
		app.getEmployeeData();
	}catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
	
}

